/*
 * @Description:
 * @Author: 赵大壮
 * @Date: 2021-12-06 17:18:37
 * @LastEditTime: 2021-12-06 17:36:29
 * @LastEditors: 赵大壮
 */
import dzMsgBox from "@/utils/DZMessageBox";
import { Component, Vue, Inject } from "vue-property-decorator";
import DZServiceCompany from "../service/DZServiceCompany";
import UiDialogAddCompany from "@/components/ui-dialog/UiDialogAddCompany.vue"
import UiDialogCompanyCover from "@/components/ui-dialog/UiDialogCompanyCover.vue"
import DZModelCompany from "../model/DZModelCompany";

@Component({
    components: { UiDialogAddCompany, UiDialogCompanyCover },
})
export default class Index extends Vue {

    s_company = new DZServiceCompany();

    dialog_add_company = false;
    
    dialog_report_cover = false;

    created() { }

    mounted() {
        this.action_list_company();
    }

    action_list_company() {
        this.s_company.net_list_company();
    }

    beforeDestroy() { }

    action_company_staff(item) {
        this.$router.push({ path: "/company/staff", query: { id: item.id, name: item.name, father: this.$route.path } })

    }
    action_frozen(item) {
        var btnMsg = item.status == 1 ? '冻结' : '解冻';
        var msg = item.name + "，是否" + btnMsg + "该公司"
        dzMsgBox.normal(msg, btnMsg, () => {
            this.action_frozen_do(item.id);
        })
    }
    action_frozen_do(id) {
        this.s_company.net_frozen_company(id, () => {
            this.action_list_company();
        });
    }
    action_del(item) {
        var msg = item.name + "，是否删除该公司"
        dzMsgBox.del(msg, () => {
            this.action_del_do(item.id);
        })
    }
    action_del_do(id) {
        this.s_company.net_del_company(id, () => {
            this.action_list_company();
        });
    }

    action_add_company(data: DZModelCompany) {
        this.dialog_add_company = false;
        this.s_company.m_company = data;
        if (this.s_company.m_company.id) {
            this.s_company.net_edit_company(() => {
                this.s_company.m_company = new DZModelCompany();
                this.action_list_company();
            });
        } else {
            this.s_company.net_add_company(() => {
                this.s_company.m_company = new DZModelCompany();
                this.action_list_company();
            });
        }
    }

    action_page_change(cur_page) {
        this.s_company.m_page.page = cur_page;
        this.action_list_company();
    }
    action_edit_company(item) {
        this.s_company.m_company = JSON.parse(JSON.stringify(item))
        this.dialog_add_company = true;
    }
}
